package com.ruoyi.web.controller.wisdom;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.wisdom.domain.FzServiceComplaint;
import com.ruoyi.wisdom.service.IFzServiceComplaintService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 投诉信息Controller
 * 
 * @author ruoyi
 * @date 2020-03-05
 */
@Controller
@RequestMapping("/wisdom/complaint")
public class FzServiceComplaintController extends BaseController
{
    private String prefix = "wisdom/complaint";

    @Autowired
    private IFzServiceComplaintService fzServiceComplaintService;

    @RequiresPermissions("wisdom:complaint:view")
    @GetMapping()
    public String complaint()
    {
        return prefix + "/complaint";
    }

    /**
     * 查询投诉信息列表
     */
    @RequiresPermissions("wisdom:complaint:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpSession session,FzServiceComplaint fzServiceComplaint)
    {
        startPage();
        fzServiceComplaint.setcId(GetSessionValueUtil.getCommunity());
        List<FzServiceComplaint> list = fzServiceComplaintService.selectFzServiceComplaintList(fzServiceComplaint);
        return getDataTable(list);
    }

    /**
     * 导出投诉信息列表
     */
    @RequiresPermissions("wisdom:complaint:export")
    @Log(title = "投诉信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzServiceComplaint fzServiceComplaint)
    {
        List<FzServiceComplaint> list = fzServiceComplaintService.selectFzServiceComplaintList(fzServiceComplaint);
        ExcelUtil<FzServiceComplaint> util = new ExcelUtil<FzServiceComplaint>(FzServiceComplaint.class);
        return util.exportExcel(list, "complaint");
    }

    /**
     * 新增投诉信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存投诉信息
     */
    @RequiresPermissions("wisdom:complaint:add")
    @Log(title = "投诉信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzServiceComplaint fzServiceComplaint)
    {     fzServiceComplaint.setComplaintId(HeadNum.COMPLAINT_HEAD+ DateUtils.getTimeMillis());
          fzServiceComplaint.setcId(GetSessionValueUtil.getCommunity());
          fzServiceComplaint.setCreateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzServiceComplaintService.insertFzServiceComplaint(fzServiceComplaint));
    }

    /**
     * 修改投诉信息
     */
    @GetMapping("/edit/{complaintId}")
    public String edit(@PathVariable("complaintId") String complaintId, ModelMap mmap)
    {
        FzServiceComplaint fzServiceComplaint = fzServiceComplaintService.selectFzServiceComplaintById(complaintId);
        mmap.put("fzServiceComplaint", fzServiceComplaint);
        return prefix + "/edit";
    }

    /**
     * 修改保存投诉信息
     */
    @RequiresPermissions("wisdom:complaint:edit")
    @Log(title = "投诉信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzServiceComplaint fzServiceComplaint)
    {
        fzServiceComplaint.setUpdateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzServiceComplaintService.updateFzServiceComplaint(fzServiceComplaint));
    }

    /**
     * 删除投诉信息
     */
    @RequiresPermissions("wisdom:complaint:remove")
    @Log(title = "投诉信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzServiceComplaintService.deleteFzServiceComplaintByIds(ids));
    }
}
